package ntu.metaweb.result;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import ntu.metaweb.storage.WebPageQuery;

@XStreamAlias("xmlresponse")
public class PageLinks {
	
	@XStreamAlias("alllinks")
	public LinkSet allLinks;
	@XStreamAlias("userlinks")
	public LinkSet userLinks;
	
	public PageLinks(String user, WebPageQuery webpagequery) {
		this.allLinks = new LinkSet();
		this.userLinks = new LinkSet();
		for (ntu.metaweb.storage.Link link : webpagequery.getOutLink().values()) {
			Link temp = new Link(user, false, link);
			if (link.getContributors().size() > 0) {
				this.allLinks.linkfrom.add(temp);
			}
			if (link.getContributors().contains(user)) {
				this.userLinks.linkfrom.add(temp);
			}
		}
		for (ntu.metaweb.storage.Link link : webpagequery.getInLink().values()) {
			Link temp = new Link(user, true, link);
			if (link.getContributors().size() > 0) {
				this.allLinks.linkto.add(temp);
			}
			if (link.getContributors().contains(user)) {
				this.userLinks.linkto.add(temp);
			}
		}
	}
}
